package com.zx.easy.service.impl;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zx.easy.converter.MapStructConverter;
import com.zx.easy.dao.UserMapper;
import com.zx.easy.pojo.dto.UserReadDto;
import com.zx.easy.pojo.entity.User;
import com.zx.easy.pojo.vo.UserExportVo;
import com.zx.easy.service.UploadDataListener;
import com.zx.easy.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    MapStructConverter mapStructConverter;
    
    @Override
    public String upload(MultipartFile file) throws IOException {

        EasyExcel.read(file.getInputStream(), UserReadDto.class, new UploadDataListener(this)).sheet().doRead();
        return "success";

    }

    @Override
    public List<UserExportVo> testMapStruct() {
        List<User> list = this.list();
       
        return mapStructConverter.userListToVoList(list);
    }

}
